<template>
  <div>
    <h1>用户冻结待审核</h1>
    <el-table
        :data="tableData.records"
        stripe
        style="width: 100%">
      <el-table-column
          prop="userName"
          label="用户名"
          width="">
      </el-table-column>
      <el-table-column
          prop="realName"
          label="真实姓名"
          width="">
      </el-table-column>
      <el-table-column
          prop="firm"
          label="公司名称">
      </el-table-column>
      <el-table-column
          prop="sex"
          label="性别"
          width="">
      </el-table-column>
      <el-table-column
          prop="phone"
          label="手机号"
          width="">
      </el-table-column>
      <el-table-column
          prop=""
          label="操作"
          width="">
        <template #default="scope">
          <el-button type="primary" @click="freeze(scope.row.userId)">查看审核详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        background
        layout="prev, pager, next, jumper"
        :total="tableData.total"
        @current-change="init"
    />
    <el-dialog
        v-model="showFreeze"
        title="审核用户信息"
        width="40%"
    >

      <el-form :model="userObj" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名" prop="userName">
          {{ userObj.userName }}
        </el-form-item>
        <el-form-item label="真实姓名" prop="realName">
          {{ userObj.realName }}
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          {{ userObj.sex }}
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          {{ userObj.phone }}
        </el-form-item>
        <el-form-item label="公司名称" prop="firm">
          {{ userObj.firm }}
        </el-form-item>
        <el-form-item label="当前余额" prop="money">
          {{ userObj.money }}
        </el-form-item>
        <el-form-item label="累计充值" prop="allMoney">
          {{ userObj.allMoney }}
        </el-form-item>
        <el-form-item label="资质证图片">
          <el-image
              style="width: 150px; height: 150px"
              :src="url1"
              :preview-src-list="srcLis1t">
          </el-image>
        </el-form-item>
        <el-form-item label="身份证图片">
          <el-image
              style="width: 150px; height: 150px"
              :src="url2"
              :preview-src-list="srcList2">
          </el-image>
        </el-form-item>
        <el-form-item label="冻结原因" prop="frozenCause">
         {{userObj.frozenCause}}
        </el-form-item>
        <el-form-item>
          <el-button type="success" @click="success()">冻结</el-button>
          <el-button type="danger" @click="failed()">不冻结</el-button>
          <el-button type="primary" @click="hidden()">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      currentPage: 1,
      pageSize: 3,
      tableData: {},
      userObj: {},
      showFreeze: false,
      url1: '',
      url2: '',
    }
  },
  methods: {
    init(pageNO) {
      this.currentPage = pageNO
      axios.get("/project/user/findByUserFreezeStatus",{
        params:{
          pageNO
        }
      }).then(resp => {
        this.tableData = resp.data
        console.log(this.tableData)
      })
    },
    hidden() {
      this.showFreeze = false
    },
    success() {
      axios.get("/project/user/updateFreezeStatus", {
        params: {
          userId: this.userObj.userId,
          status: 1,
        }
      }).then(resp => {
        if (resp.data == "ok") {
          this.$message({
            message: "审核成功",
            type: "success",
            showClose: true,
          });
          this.showFreeze = false
        }
      })
    },
    failed(){
      axios.get("/project/user/updateFreezeStatus", {
        params: {
          userId: this.userObj.userId,
          status: 0,
        }
      }).then(resp => {
        if (resp.data == "ok") {
          this.$message({
            message: "审核成功",
            type: "success",
            showClose: true,
          });
          this.showFreeze = false
          this.init(1)
        }
      })
    },
    freeze(userId) {
      this.showFreeze = true
      axios.get("/project/user/findById", {
        params: {
          userId
        }
      }).then(resp => {
        this.userObj = resp.data
        this.url1 = this.userObj.aptitudeImg
        this.url2 = this.userObj.idImage
        this.init(1)
      })
    }
  },
  created() {
    this.init(1)
  }
}
</script>

<style scoped>

</style>